﻿using MXERP.Shared.Enums;
using MXERP.Shared.Extensions;

namespace MXERP.Shared.Wrapper
{
    /// <summary>
    /// 返回Model
    /// </summary>
    public class ApiResponse
    {
        public ApiResponse()
        {
            Status = (int)ApiStatusEnum.Success;
        }
        public ApiResponse(dynamic data)
        {
            Data = data;
            Status = (int)ApiStatusEnum.Success;
        }
        public ApiResponse(string message)
        {
            Message = message;
            Status = (int)ApiStatusEnum.Success;
        }

        public ApiResponse(ApiStatusEnum apiStatusEnum, string message = "")
        {
            Status = (int)apiStatusEnum;
            Message = message;
        }

        public ApiResponse(int apiStatus, string message = "")
        {
            Status = apiStatus;
            Message = message;
        }
        /// <summary>
        /// 状态码
        /// </summary>
        public int Status { get; set; }
        private string? message;
        /// <summary>
        /// 信息
        /// </summary>
        public string? Message
        {
            get
            {
                return string.IsNullOrWhiteSpace(message)
                    ? Status.GetDescription<ApiStatusEnum>()
                    : message;
            }
            set
            {
                message = value;
            }
        }
        /// <summary>
        /// 结果集
        /// </summary>
        public object? Data { get; set; }
        public bool IsSuccess
        {
            get { return Status == (int)ApiStatusEnum.Success; }
        }
    }
    /// <summary>
    /// 返回Model
    /// </summary>
    public class ApiResponse<T> where T : class
    {
        public ApiResponse()
        {
            Status = (int)ApiStatusEnum.Success;
        }
        public ApiResponse(T data)
        {
            Data = data;
            Status = (int)ApiStatusEnum.Success;
        }
        public ApiResponse(string message)
        {
            Message = message;
            Status = (int)ApiStatusEnum.Success;
        }

        public ApiResponse(ApiStatusEnum apiStatusEnum, string message = "")
        {
            Status = (int)apiStatusEnum;
            Message = message;
        }

        public ApiResponse(int apiStatus, string message = "")
        {
            Status = apiStatus;
            Message = message;
        }
        /// <summary>
        /// 状态码
        /// </summary>
        public int Status { get; set; }
        private string? message;
        /// <summary>
        /// 信息
        /// </summary>
        public string? Message
        {
            get
            {
                return string.IsNullOrWhiteSpace(message)
                    ? Status.GetDescription<ApiStatusEnum>()
                    : message;
            }
            set
            {
                message = value;
            }
        }
        /// <summary>
        /// 结果集
        /// </summary>
        public T Data { get; set; }
        public bool IsSuccess
        {
            get { return Status == (int)ApiStatusEnum.Success; }
        }
    }
}